// src/store/system.js
import { defineStore } from 'pinia';

export const useSystemStore = defineStore('system', {
  state: () => ({
    // 系统配置
    config: {
      title: '十二相发电机组仿真教学系统',
      version: '1.0.0',
      apiUrl: '/api'
    },
    // 系统状态
    status: {
      loading: false,
      online: true,
      lastUpdate: null
    },
    // 通知消息
    notifications: []
  }),

  getters: {
    // 获取系统标题
    systemTitle: (state) => state.config.title,
    
    // 获取是否有未读通知
    hasUnreadNotifications: (state) => state.notifications.some(n => !n.read)
  },

  actions: {
    // 设置加载状态
    setLoading(loading) {
      this.status.loading = loading;
    },

    // 添加通知
    addNotification(notification) {
      this.notifications.push({
        id: Date.now(),
        read: false,
        timestamp: new Date(),
        ...notification
      });
    },

    // 标记通知为已读
    markAsRead(id) {
      const notification = this.notifications.find(n => n.id === id);
      if (notification) {
        notification.read = true;
      }
    },

    // 清除所有通知
    clearNotifications() {
      this.notifications = [];
    }
  }
});